package com.itany.corejava.code07_面向对象;

/**
 * @author: 石小俊
 * @date: 2023年03月07日 11:17
 * @version: 1.0
 */
public class User {
    int id;
    String username;
    String password;
    public User(String username,String password){
        System.out.println("这是有参的构造方法");
        this.username = username;
        this.password = password;
    }

    public User(int id,String username,String password){
        this(username,password); // 只能处于第一行
        this.id = id;
    }

    public User(){
        System.out.println("这是无参构造方法");
    }

    public void show(){
        System.out.println("id:"+id+",username:"+username+",password:"+password);
    }
}
class TestUser{
    public static void main(String[] args) {
        User user = new User("admin","123");
        user.show();
        User user2 = new User();
        user2.id = 2;
        user2.username = "tom";
        user2.show();

        User user3 = new User(1,"alice","123456");
        user3.show();
    }
}
